
		var setting = {  
	            async: {  
	                enable: false,//异步处理  
	                //url: tdmPath+'/item/ajaxTree.jhtml?moduleId='+moduleId,//异步获取json格式数据的路径               
	            },
	            view: {
	            	addDiyDom: addDiyDomWithCheck,
	            	addHoverDom: getNodetype,
	            	removeHoverDom: removeHoverDom,
	                dblClickExpand: false,//双击节点时，是否自动展开父节点的标识
	                showLine: false,//是否显示节点之间的连线
	                //showIcon:false,
	                fontCss:{
	                	'color':'#000'
	                	},//字体样式函数
	    
	                selectedMulti: false //设置是否允许同时选中多个节点
	              },
	              edit: { 
	            	  drag:{
	            		  isCopy: false,
	            		  isMove: false
	            		  },
	                  enable: true, //单独设置为true时，可加载修改、删除图标  
	          		  showRenameBtn: true,
	          		  showRemoveBtn: false
	              },  
	            callback: {//回调函数，在这里可做一些回调处理  
	                //beforeAsync: zTreeBeforeAsync 
	            	onAsyncSuccess: function(event, treeId,nodes,msg){
	            		/*  if(msg.length==2){
	            			str = "<div id='no_tree' class='text-center' style='margin-top:20px;'><label class='glyphicon glyphicon-hand-right text-primary' aria-hidden='true' ></label>&nbsp;&nbsp;暂无数据</div>"
	            			$("#tree_data").html(str);
	            			
	            		}
*/							
				       // zTreeObj.expandAll(true);
	            	},
	            	onRename: onRename, //修改事件
	            	onClick: function(event, treeId, treeNode){
	            		if(treeNode.type=='0'){
	            			
	            			doc_id = treeNode.id;
	            			docDetail(treeNode.id);
	            		}
	            	},
	            	beforeRename: zTreeBeforeRename
	            },  
	            check: {//设置 zTree 的节点上是否显示 checkbox / radio ,默认为false  
	                enable: true,
	                chkboxType:  { "Y": "", "N": "" }
	            }, 
	            data: {  
	                simpleData: {                     
	                    enable: true,//true / false 分别表示 使用 / 不使用 简单数据模式  
	                    idKey: "id",  
	                    pIdKey: "pId",  
	                    rootPId: 0                            
	                }  
	            }  
	        };  
		
		function zTreeBeforeRename(treeId, treeNode, newName, isCancel){
			//alert(treeNode.name)
			/*if(treeNode.name==newName){
				isCancel = false
			}else{
				onRename()
			}*/
		}
		
		function loginOut(){
			layer.confirm('确定要退出吗？', {icon: 7, title:'提示'}, function(index){
				  //do something
		            location.href = tdmPath+"/main/login_out.jhtml";
				  layer.close(index);
				});
		}
		
		function onRename(e, treeId, treeNode, isCancel) {  
 
		   if(treeNode.name==""){
			   layer.msg("名字不能为空");
		   }else{
			   $.ajax({
					type : 'POST',
					dataType : 'JSON',
					url : tdmPath + "/item/update.jhtml",
					data : {
						name : treeNode.name,
						id : treeNode.id,
						type : treeNode.type
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						layer.msg("系统错误");
					},
					success : function(data) {
						if (data.responseCode == "1") {
							if(treeNode.type=='0'){
								docDetail(treeNode.id);
							}
							layer.msg("修改成功");
							getTree(module_id);
						} else {
							layer.msg("修改失败");
						}
					}
				});
		   } 
		} 
		
		
		function getNodetype(treeId, treeNode) {  
		    
			//$('#'+treeNode.tId+'_span').css('background','#014a6d')
		   // $('#'+treeNode.tId+'_span').css('color','#fff')
		    $('#'+treeNode.tId+'_a').css('text-decoration','none')
		    $('#'+treeNode.tId+'_a').css('background','none')
		    $('#'+treeNode.tId+'_a').css('border','none')
		} 
		function removeHoverDom(treeId, treeNode) {  
				    
			$('#'+treeNode.tId+'_span').css('background','none')
			//$('#'+treeNode.tId+'_span').css('color','#fff')	   
			$('#'+treeNode.tId+'_a').css('background','none')
			 $('#'+treeNode.tId+'_a').css('border','none')
		} 
		
		
		function addDiyDomWithCheck(treeId, treeNode) {
			/* var spaceWidth = 5;
			 var switchObj = $("#" + treeNode.tId + "_switch"),
			 checkObj = $("#" + treeNode.tId + "_check"),
			 icoObj = $("#" + treeNode.tId + "_ico");
			 
			 switchObj.remove();
			 checkObj.remove();
			 icoObj.parent().before(switchObj);
			 icoObj.parent().before(checkObj);
			 */
			 $("#" + treeNode.tId + "_span").css({"fontSize":14});
				if(userId!=''||userId!=""){
					 var spantxt = $("#" + treeNode.tId + "_span").html();
					 $("#" + treeNode.tId + "_span").attr("data-toggle","tooltip");
					 $("#" + treeNode.tId + "_span").attr("data-placement","top");
					 if (spantxt.length > 9) {
						  spantxt = spantxt.substring(0,5) + "..";
						  $("#" + treeNode.tId + "_span").html(spantxt);
					 }
				}
			 
			}
		
		//设置左侧div宽度为浏览器的高度
		$(function() {
			
			window.onresize = function () { 
			/*	var w_height = $(window).height();
				var w_width = $(window).width();
				$('#main_bg').height(w_height);
				$('#main_bg').width(w_width);
				console.info(w_height+"\n"+w_width);*/
			}
			
			
			$('#treeView').css("height", $(window).height() - 52);
			$('#doc_panel').css("height", $(window).height() - 64);
			$('#doc_panel').css("width", $(window).width()-190);
			$('#hide_icon').css("height", $(window).height() - 53);
			$('#main_content').css("height", $('#doc_panel').height());
			$('#main_content').css("width", $('#doc_panel').width()-21);
			$('#doc_panel_content').css("height", $(window).height() - 53);
			$('#no_doc').css("margin-top", $(window).height()/2-50);
			$('#no_tree').css("margin-top", $(window).height()/2-100);
			$('#turn_icon').css("top", $(window).height()/2-100);
			var id = $('#navBar li').first().attr("class");
			
			module_name = $("ul li").first().children("a:eq(0)").html();
			getTree(id);
		});
		
		
		function saveDoc(){
			 var docContent = $("#editormdResult").val();
			  var docTitle = $("#docTitle").val();
			  var id = $("#doc_id").val();
			  var formType = $("#formType").val();
			  var item_id = "";
			  var arr=zTreeObj.getCheckedNodes(true);
			  if(arr.length>0){
				  item_id = arr[0].id;
				}
             if(docTitle==""){
           	  layer.msg('请输入文档标题');
           	  return;
             }else if(docContent==""){
           	  layer.msg('请输入文档内容');
           	  return;
             }else if(item_id==""&&formType=="1"){
           	  layer.msg('请选择所属类别');
           	  return;
             }else{
	              $.post(tdmPath + '/doc/add.jhtml', {
	  				itemId : item_id,
	  				content:docContent,
	  				title:docTitle,
	  				id :id
	  				}, function(e) {
	  					//修改成功
		  				if (e.responseCode == "1") {
		  					getTree(module_id);
		  				} else if(e.responseCode == "2"){
		  					getTree(module_id);
		  					docDetail(e.responseMsg);
		  					layer.msg("添加成功");
		  				}
		  				$('#submit_btn').html("保存");
	  			},"json")
             }
             
              
		}
	

		//文档详情/修改界面
		function docDetail(id){
			var index = '';
			if(userId==''||userId==""){
				index = layer.load();
			}
			$.ajax({
				url:tdmPath+"/doc/docDetail.jhtml",
			    global: false,
			    cache:false, 
			    type: "GET",
			    data : {
					id : id,
					formType:"0",//1,为天机界面，0为修改界面
				},
			    dataType: "html",
			    success: function(msg) {
			    	layer.close(index);
			    	$("#main_content").html(msg);
			      }
			})
			
		}
		
		//添加界面
		function newDoc(){
			
			var arr = "";
			if(zTreeObj!=undefined){
				arr=zTreeObj.getCheckedNodes(true);
			}
			var ids = [];
			var type  =""
			if(arr!=''||arr!=""){
				type = arr[0].type;
			}
			$.each(arr, function(key) {
				ids.push(arr[key].id);
			});
			id = ids.join(',');
			if (ids.length==0||ids.length>1) {
				 layer.msg("请选择一条记录");
				return;
			}else if(type=='0'){
				layer.msg("文档下面不能添加文档");
			}else{
				$.ajax({
					url:tdmPath+"/doc/docDetail.jhtml",
				    global: false,
				    type: "GET",
				    data : {
						itemId : id,
						formType:"1",//1,为天机界面，0为修改界面
					},
				    dataType: "html",
				    cache:false, 
				    success: function(msg) {
				    	$("#main_content").html(msg);
				      }
				})
			}
			
		}
		//模块删除
		function delModule(id){
		
				layer.confirm('确定要删除吗？', {icon: 7, title:'提示'}, function(index){
					if(id!=""){
						$.ajax({
							type : 'GET',
							dataType : 'JSON',
							url : tdmPath+"/module/del.jhtml",
							data : {
								id : id
							},
							error : function(XMLHttpRequest, textStatus, errorThrown) {
								$("#msg").html("系统错误！！");
							},
							success : function(data) {
								if (data.responseCode == "1") {
									window.location.href = tdmPath;
								}else if(data.responseCode == "2"){
									layer.msg("请删除其下的子菜单");
								}
							}
						});
					}
				layer.close(index);
			})
		}
		
		function moduleAlert(){
			layer.open({
			    id:3,
		        type: 1,
		        shift:1,
		        shadeClose:true,
		        title:['添加模块', 'font-size:16px;'],
		        area:['300px', '180px'],
		        
		        content:' <div style="margin:10px;">'
		            +'<input id="addModelu" name="addModelu"  type="text" class="form-control" placeholder="请输入模块名">'
		            +'</div>'
		        ,
		        btn:['添加','取消'],
		        btn1: function (index,layero) {
		        	var addModelu = $('#addModelu').val();
		        	if(addModelu==""||addModelu==''){
						  layer.tips('必填', '#addModelu',{
							  tips: [2, '#266c8b'],
							  time: 1000
							});
					  }else{
						  $.ajax({
								type : 'POST',
								dataType : 'JSON',
								url : tdmPath + "/module/add.jhtml",
								data : {
									moduleName : addModelu
								},
								error : function(XMLHttpRequest, textStatus, errorThrown) {
									layer.msg("系统错误！！");
								},
								success : function(data) {
									if (data.responseCode == "1") {
										window.location.href = tdmPath;
										layer.close(index);
									} else {
										layer.msg("添加失败！！");
									}
								}
							});
					  }
		    	},
		        btn2:function (index,layero) {
		        	 layer.close(index);
		        }

		    });
			
			/*layer.prompt({
			    formType: 0,
			    title: ['模块添加', 'font-size:18px;'],
			    shadeClose:true,
			    shift:1
			  }, function(value, index, elem){
				layer.close(index);
			    
			  });*/
				/*$("#myModal").modal({
					remote:tdmPath+"/module/addUI.jhtml"
				});*/
		}
		
		function loginUI(){

			layer.open({
				    id:3,
			        type: 1,
				    shift:1,
			        shadeClose:true,
			        title:['用户登录', 'font-size:16px;'],
			        area:['300px', '220px'],
			        content:' <div style="margin:10px;">'
			            +'<input id="uname" name="name"  type="text" class="form-control" placeholder="请输入用户名">'
			            +'</div>'
			              +'<div style="margin:10px">'
			              +'<input id="upwd" name="pwd"  type="password" class="form-control" placeholder="请输入密码">'
			              +'</div>'
			        ,
			        btn:['登录','取消'],
			        btn1: function (index,layero) {
			        	var name = $('#uname').val();
			        	var pwd = $('#upwd').val();
			        	Check(name,pwd)
			    	},
			        btn2:function (index,layero) {
			        	 layer.close(index);
			        }

			    });
			
	}
		
		
		
		function Check(uname,pwd) {
			if (uname == "") {
				layer.tips('必填', '#uname',{
					  tips: [2, '#266c8b'],
					  time: 1000
					});
				//layer.msg("请输入完整信息")
				return false;
			} else if(pwd == "") {
				layer.tips('必填', '#upwd',{
					  tips: [2, '#266c8b'],
					  time: 1000
					});
			}else{
				$.ajax({
					type : 'POST',
					dataType : 'JSON',
					url : basePath + '/main/login_check.do',
					data : {
						name : uname,
						pwd : pwd
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						layer.msg("系统错误！！")
					},
					success : function(data) {
						var code = data.responseCode;
						if (code == "1") {
							window.location.href = tdmPath;
						} else {
							layer.msg("用户不存在")
						}

					}
				});
			}

		}
		
		
		//通过模块id获取其子菜单树
		function getTree(moduleId,moduleName){
			$('#no_doc').show();
			var alist = $('#navBar li')
			for(var i =0;i < alist.length;i++){
				alist[i].className && $('.'+alist[i].className).css('background-color','') 
			} 
			$('.'+moduleId).css('background-color','#279b90'); 
			if(moduleName!=''){
				module_name = moduleName
			}
			var zNodes;
			 $.ajax({
		              type: "Get",    
		              url: tdmPath+'/item/ajaxTree.jhtml?moduleId='+moduleId,          
		              dataType: "json",     
		               global: false,             
		              async: false,                      
		               success: function (strReult) {
		            	   module_id = moduleId;
		                   zNodes=strReult; 
		              },    
		             error: function () {   
		                alert("Ajax请求数据失败!");
		             }
		             });
			 	
			 	if(zNodes!=undefined&&zNodes.length>0){
			 		$("#no_tree").hide();
			 		$("#permission_tree").show();
				 	zTreeObj = $.fn.zTree.init($("#permission_tree"), setting,zNodes);
				 	zTreeObj.expandAll(true);
			 	}else{
            		$("#no_tree").show();
            		$("#permission_tree").hide();
			 	}
			 	if(userName==""||userName==''){
				 	$.fn.zTree.destroy("#permission_tree");
				 	setting.check.enable=false;
				 	setting.edit.showRenameBtn = false;
				 	zTreeObj = $.fn.zTree.init($("#permission_tree"), setting,zNodes);
				 	zTreeObj.expandAll(true);
			 	}
				 
		}


		//菜单节点删除
		function delNodes(id) {
			var arr = "";
			if(zTreeObj!=undefined){
				arr=zTreeObj.getCheckedNodes(true);
			}
			var ids = [];
			$.each(arr, function(key) {
				ids.push(arr[key].id);
			});
			id = ids.join(',');
			if (id == null || id == "") {
				 layer.msg('至少选择一条记录');
				return;
			} else {
				layer.confirm('确定要删除吗？', {icon: 7, title:'提示'}, function(index){
					$.ajax({
						type : 'POST',
						dataType : 'JSON',
						url : tdmPath + "/doc/del.jhtml",
						data : {
							ids : id
						},
						error : function(XMLHttpRequest, textStatus, errorThrown) {
							$("#msg").html("系统错误！！");
						},
						success : function(data) {
							if (data.responseCode == "1") {
								getTree(module_id);
								$('#main_content').html('<div style="width:150px; height:100px;  margin:auto;" id="no_doc" ><img alt="" src="./images/no_doc.png" width="150px;" height="100px"  style="margin:auto"></div>');
								$('#no_doc').css("margin-top", $(window).height()/2-50);
							} else {
								$("#msg").html("删除失败！");
							}
						}
					});
					layer.close(index);
				});
				
			}
		}
		

		//ajax 子菜单添加操作
		function addItem(id,value,index) {
			var arr = "";
			if(zTreeObj!=undefined){
				arr=zTreeObj.getCheckedNodes(true);
			}
			if(zTreeObj!=undefined){
				arr=zTreeObj.getCheckedNodes(true);
			}
			var ids = [];
			$.each(arr, function(key) {
				ids.push(arr[key].id);
			});
			id = ids.join(',');
			if (module_id != '' || module_id != "") {
				$.ajax({
					type : 'POST',
					dataType : 'JSON',
					url : tdmPath + "/item/add.jhtml",
					data : {
						moduleId : module_id,
						pid : id,
						itemName : value
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						layer.msg("系统错误！！");
					},
					success : function(data) {
						if (data.responseCode == "1") {
							getTree(module_id);
							layer.close(index);
							layer.msg("添加成功！！");
							
						} else {
							layer.msg("添加失败！");
						}
					}
				});
			}

		}
		
		function docGramar(){
			window.open(tdmPath+'/doc/gramar.jhtml')
			/* $("#gramarUI").modal({
				remote:tdmPath+"/doc/gramar.jhtml?id=1"
			}); */
		}
		
		
		function itemAlert(){ 
			var arr = "";
			if(zTreeObj!=undefined){
				arr=zTreeObj.getCheckedNodes(true);
			}
			
			var ids = [];
			item_name = "";
			level = "";
			type="";
			if(arr.length>0){
			    item_name = arr[0].name;
			    level = arr[0].level;
			    type = arr[0].type;
			}
			$.each(arr, function(key) {
				ids.push(arr[key].id);
			});
			id = ids.join(',');
			if (ids.length >= 2){
				 layer.msg('请选择一条记录');
				return false;
			} else if(type=='0'){
				layer.msg('文件不能添加二级菜单');
			}else if(level>=1){
				layer.msg('只能添加到二级菜单');
			}else{
				/*$("#itemModal").modal({
					remote:tdmPath+"/item/addUI.jhtml?itemName="+item_name+"&moduleName"+module_name,
					
				});*/
				if(item_name==""&&module_name!=undefined){
					item_name = module_name;
				}
				layer.open({
				    id:3,
			        type: 1,
			        shift:3,
			        shadeClose:true,
			        title:[item_name+'添加子菜单', 'font-size:16px;'],
			        area:['300px', '180px'],
			        content:' <div style="margin:10px;">'
			            +'<input id="addItemname" name="addItemname"  type="text" class="form-control" placeholder="请输入子菜单">'
			            +'</div>'
			        ,
			        btn:['添加','取消'],
			        btn1: function (index,layero) {
			        	var addItemname = $('#addItemname').val();
			        	if(addItemname==""||addItemname==''){
							  layer.tips('必填', '#addItemname',{
								  tips: [2, '#266c8b'],
								  time: 1000
								});
						  }else{
							  addItem(id,addItemname,index);
						  }
			    	},
			        btn2:function (index,layero) {
			        	 layer.close(index);
			        }

			    });
				
			}
		}